from models.model import Model
from torch import nn
import torch.nn.functional as F


class LeNet(Model):
    fc1_in_features:int

    def __init__(self,dst):
        super(LeNet,self).__init__(dst)
        self.conv1 = nn.Conv2d(self.in_channels, 16, kernel_size=5, stride=1)
        self.pool1 = nn.MaxPool2d(2, 2)
        self.conv2 = nn.Conv2d(16, 32, kernel_size=5, stride=1)
        self.pool2 = nn.MaxPool2d(2, 2)
        self.fc1 = nn.Linear(self.fc1_in_features, 120)
        self.fc2 = nn.Linear(120, 84)
        self.fc3 = nn.Linear(84, 10)


    def forward(self,x):
        out = F.relu(self.conv1(x))
        out = self.pool1(out)
        out = F.relu(self.conv2(out))
        out = self.pool2(out)
        out = out.view(-1, self.fc1_in_features)
        out = F.relu(self.fc1(out))
        out = F.relu(self.fc2(out))
        out = self.fc3(out)

        return out


    def _get_fc1_in_features_size(self):
        c1:int = int((self.data_size - 4)/2)
        c2:int = int((c1 - 4)/2)
        self.fc1_in_features = c2 * c2 * 32